<template>
	<view>
		<view class="head">
			<view class="head_left" @tap="back()">
				<image src="../../../static/wode/return.png" mode=""></image>
				<text>返回</text>
			</view>
			<view class="head_mid">
				发红包
			</view>
			<view class="head_left">

			</view>
		</view>
		<view class="padding-box">
			<view class="item">
				<view class="">
					猫币总额
				</view>
				<view class="item_right">
					<input type="number" class="moneyNum" v-model="money" @input="changeMoney">
					<text>猫币</text>
				</view>
			</view>
			<input class="item" type="text" v-model="text1" value="" placeholder="财源滚滚" />
			<view class="btn" v-if="hasMoney==true" @tap="tomoney">
				塞钱进红包
			</view>
			<view class="btn btn2" v-else>
				塞钱进红包
			</view>
		</view>
		<pay :money="money" :isShow="isShow" :duration="duration" :newMember_level="newMember_level" :paytype="paytype"></pay>
		<mask :isShowMask='isShowMask' @closeMask='closeMask'></mask>

	</view>
</template>

<script>
	import pay from '../../../components/pay.vue'
	import mask from '../../../components/mask.vue'
	export default {
		components: {
			pay,
			mask
		},
		data() {
			return {
				hasMoney: false,
				money: '',
				text1: '',
				isShow: false,
				isShowMask: false,
				myInfo: uni.getStorageSync('user_info'),
				payment_id: '',
			}
		},
		onLoad(option) {
			this.payment_id = option.item
			this.chatType = option.chatType
			this.MsgSeq = option.MsgSeq
			console.log(this.payment_id, '收钱id')
		},
		methods: {
			changeMoney() {
				var containSpecial = RegExp(
					/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)(\u4e00-\u9fa5)(A-Za-z)]+/
				);
				if (containSpecial.test(this.money) == true || this.money == '' || this.money <= 0) {
					this.hasMoney = false
					this.money = ''
					uni.showToast({
						title: '请输入正确金额',
						icon: 'none'
					})
				} else {
					this.hasMoney = true
				}
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			tomoney() {
				// this.isShow=true;
				// this.isShowMask=true;
				var mymoney = this.myInfo.cat_coin
				if (mymoney < this.money) {
					uni.showToast({
						title: '猫币余额不足',
						icon: 'none'
					})
					return
				} else {
					this.setRed()

				}
			},
			setRed() {
				var me = this;
				if(this.text1==''){
					this.text1='财源滚滚'
				}
				var data = {
					user_id: uni.getStorageSync('user_id'),
					type: 'redenvelopes',
					payment_id: this.payment_id,
					pay_count: this.money,
					status:1,
				}
				this.myAjaxNewPost({
					model: 'user',
					controllerName: 'userOrder',
					actionName: 'insert',
					data: data,
					successBack: function(res) {
						console.log(res.data)
						if (res.data.message == '成功') {
							uni.navigateBack({
								delta:1
							})
							var redData={
								order_no:res.data.data,
								pay_count:me.money.toString(),
								payment_id:me.item,
								remarks:me.text1,
								sendNickName:uni.getStorageSync('nick_name'),
								source:'chat',
								status:"1",
								type:'redenvelopes',
								user_id:uni.getStorageSync('user_id').toString(),
							}
							uni.setStorageSync("redData",redData)
							uni.showToast({
								title: '赠送成功',
								icon: 'none'
							})
						}

					}
				})
			},
			closeMask() {
				this.isShow = false;
				this.isShowMask = false
			},

		}
	}
</script>

<style scoped>
	.head {
		width: 100%;
		display: flex;
		justify-content: space-between;
		height: 128upx;
		background: #ffffff;
		padding: 0 24upx;
		z-index: 200;
		position: fixed;
		top: 0;
		box-sizing: border-box;
	}

	.head image {
		width: 20upx;
		height: 36upx;
		margin-right: 9upx;
	}

	.head_left {
		height: 82upx;
		width: 106upx;
		display: flex;
		align-items: center;
		line-height: 82upx;
		color: #666666;
		font-size: 32upx;
	}

	.head_right {
		width: 150upx;
	}

	.padding-box {
		padding-top: 148upx;
	}

	.item {
		background: #FFFFFF;
		padding: 0 24upx;
		color: #333333;
		font-size: 32upx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 88upx;
		margin-bottom: 20upx;
	}

	.item_right {
		display: flex;
		align-items: center;
	}

	.moneyNum {
		height: 100%;
		text-align: right;
		padding-right: 10upx;
	}

	.btn {
		margin-top: 200upx;
	}

	.btn2 {
		opacity: 0.5;
	}
</style>
